﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SharingCenter.Web.Mod.Groups.Events
{
    using SharingCenter.Web.Classes;
    using SharingCenter.Web.Classes.Groups;
    using SharingCenter.Web.Classes.enums;
    using SharingCenter.Web.Classes.Events;

    public partial class Default : GroupsPageBase
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            ParseGroupIdFromQueryString();
            HasRights(groupId, Profile.UserId);
            SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(this.SiteMap_SiteMapResolve);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindIncomingEvents();
            ltrTitle.Text = group.GroupName;

        }

        private void BindIncomingEvents()
        {
            using (scDataContext cxt = new scDataContext())
            {
                lvFutureEvents.DataSource = cxt.GetIncomingEvents((int)EntityType.GroupEvent, groupId, (int)PrivacyEnum.Group, 0).ToList();
            }
            lvFutureEvents.DataBind();
            
        }

        protected void Page_Unload(object sender, EventArgs e)
        {
            SiteMap.SiteMapResolve -= new SiteMapResolveEventHandler(this.SiteMap_SiteMapResolve);
        }

        private SiteMapNode SiteMap_SiteMapResolve(object sender, SiteMapResolveEventArgs e)
        {
            SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);
            SiteMapNode tmpNode = currentNode.ParentNode;
            tmpNode.Title = group.GroupName;
            tmpNode.Url += "?id=" + groupId;
            return currentNode;
        }

    }
}
